// 根据参数日期获取具体日期信息
export const formatDate = function(date = new Date()) {
	let year = date.getFullYear();
	let month = (date.getMonth() + 1);
	let day = date.getDate();
	let week = ['天', '一', '二', '三', '四', '五', '六'][date.getDay()];

	const dateInfo = {
		date: new Date(date),
		dateStr: `${year}-${month.toString().padStart(2,'0')}-${day.toString().padStart(2,'0')}`,
		year,
		month,
		day,
		week,
		isToday: false
	}

	const today = new Date();
	// 判断是否为当天
	if (today.getFullYear() === year && (today.getMonth() + 1) === month && today.getDate() === day) {
		dateInfo['isToday'] = true;
	}
	return dateInfo;
};

// 根据基准日期获取前后某天的日期对象
export const getDateByDate = function(date = new Date(), range = 0) {
	date.setDate(date.getDate() + range);
	return date;
};

export const getCurrentDayAfter = function (date = new Date(), step = 7) {
	let weekData = [];
	const week = date.getDay() - 1;
	date = getDateByDate(date);
	for (let i = 0; i < step; i++) {
		weekData.push(formatDate(i == 0 ? date : getDateByDate(date, 1)))
	}
	return weekData;
}

export const getCurrentDay = function () {
	const today = new Date();
	let year = today.getFullYear();
	let month = (today.getMonth() + 1);
	let day = today.getDate();
	return `${year}-${month.toString().padStart(2,'0')}-${day.toString().padStart(2,'0')}`
}